%===================================================================================================
%[]FUNCTION NAME: Rotate.m
%[]AUTHOR: Jinsung Lee
%[]CREATED: 04/07/2017
%[]REVISED: 07/20/2017
%===================================================================================================
%[]FUNCTION DESCRIPTION:
%This function calculates the matrix needed to actively rotate a vector about an axis by a given
%angle using the Rodrigues rotation formula.
%===================================================================================================
%[]INPUT VARIABLES:
%(u)|Rotation axis.
%---------------------------------------------------------------------------------------------------
%(theta)|Rotation angle.
%---------------------------------------------------------------------------------------------------
%(string)|Angle units.
%===================================================================================================
%[]OUTPUT VARIABLES:
%(R)|Rotation matrix.
%===================================================================================================
%[]VARIABLE FORMAT:
%(u)|Column Vector {3 x 1}.
%---------------------------------------------------------------------------------------------------
%(theta)|Scalar {1 x 1}.
%---------------------------------------------------------------------------------------------------
%(string)|String.
%---------------------------------------------------------------------------------------------------
%(R)|Matrix {3 x 3}.
%===================================================================================================
%[]AUXILIARY FUNCTIONS:
%None.
%===================================================================================================
%[]COMMENTS:
%None.
%===================================================================================================
function R = Rotation(u,theta,string)
    
    ux = [0, -u(3), u(2); u(3), 0, -u(1); -u(2), u(1), 0];
    %[]Skew symetric matrix.
  
    uxu = u * transpose(u);
    %[]Tensor product.
    
    if strcmpi(string,'Radians') == true;
        
        R = cos(theta) * eye(3,3) + sin(theta) * ux + (1 - cos(theta)) * uxu;
        %[]Rotation matrix.
        
    elseif strcmpi(string,'Degrees') == true;
        
        R = cosd(theta) * eye(3,3) + sind(theta) * ux + (1 - cosd(theta)) * uxu;
        %[]Rotation matrix.
        
    end
    
end
%===================================================================================================